package com.itibo.services;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import com.itibo.models.MediaCollection;
import com.itibo.models.SongCollection;
import com.itibo.models.Song;

public class SongProcessor /*extends MediaCollection*/ {
	private SongCollection collectionOfSongs;
	public SongProcessor(SongCollection collection) {
		this.collectionOfSongs = collection;
	}

	public void sort(Comparator<Song> compare) {
		Collections.sort(collectionOfSongs.getMySongs(), compare);
	}

	public void showCollection() {
		for (Song song : collectionOfSongs.getMySongs()) {
			System.out.println(song);
		}
		System.out.println("");
	}

	public SongCollection getCollectionOfSongs() {
		return collectionOfSongs;
	}

	public void setCollectionOfSongs(SongCollection collectionOfSongs) {
		this.collectionOfSongs = collectionOfSongs;
	}

    public void filter(Song filterSong){
        SongCollection myNewCollection=new SongCollection();
        for (Song currentSong:collectionOfSongs.getMySongs() ){
            if (isSatisfiesFilter(currentSong, filterSong)) {
                myNewCollection.add(currentSong);
            }

        }
        collectionOfSongs=myNewCollection;
        //добавить коллекцию пустую
        //пробегаем по изначальной коллекции и добавляем если норм
    }
    private boolean isSatisfiesFilter(Song currentSong, Song filterSong) {
        boolean result = true;
        result = result && compareTwoStrings(currentSong.getAuthor(), filterSong.getAuthor());
        result = result && compareTwoStrings(currentSong.getGenres(),filterSong.getGenres());
        result = result && compareTwoStrings(currentSong.getName(),filterSong.getName());
        result = result && compareTwoStrings(currentSong.getYear(),filterSong.getYear());
        return result;
    }
    public boolean compareTwoStrings(String s1,String s2){
        return s2 == null || s2.isEmpty() || (s1 != null && s1.contains(s2));
    }
	

}
